﻿using MapleLeaf.Pay.Pay;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;

namespace MapleLeaf.Client{
    public partial class FloatWindow : Window {
        public FloatWindow() {
            DataContext = HongshPayClientContext.Default;
            InitializeComponent();
            Left = HongshPayClientContext.Default.Config.MinWindowX;
            Top = HongshPayClientContext.Default.Config.MinWindowY;
            if (HongshPayClientContext.Default.Config.IsMinWindowShow) {
                Show();
            }
            HongshPayClientContext.Default.Config.PropertyChanged += Config_PropertyChanged;
        }


        private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e) {
            if (e.PropertyName == "IsMinWindowShow") {
                if (HongshPayClientContext.Default.Config.IsMinWindowShow) {
                    Show();
                }
                else {
                    Hide();
                }
            }
        }

        private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
            (Application.Current.MainWindow as MainWindow).SwithVisible(null, null);
        }


        private void Window_MouseDown(object sender, MouseButtonEventArgs e) {
            try {
                DragMove();
            }
            catch (Exception) {
            }
        }
        protected override void OnLocationChanged(EventArgs e) {
            HongshPayClientContext.Default.Config.MinWindowX = (int)Left;
            HongshPayClientContext.Default.Config.MinWindowY = (int)Top;
            base.OnLocationChanged(e);
        }
    }
}
